package com.zrrd.mcl.product.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.zrrd.mcl.common.result.Result;
import com.zrrd.mcl.model.product.SpuInfo;
import com.zrrd.mcl.product.service.SpuInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/admin/product")
public class SpuInfoController {

    @Autowired
    private SpuInfoService spuInfoService;

    @GetMapping("/{page}/{limit}")
    public Result<Page> page(@PathVariable Integer page, @PathVariable Integer limit,Long category3Id) {
        Page<SpuInfo> pageInfo = new Page<>(page, limit);
        QueryWrapper<SpuInfo> wrapper = new QueryWrapper<>();
        wrapper.eq("category3_id", category3Id);
        spuInfoService.page(pageInfo,wrapper);
        return Result.ok(pageInfo);
    }

    @PostMapping("/saveSpuInfo")
    public Result<String> saveSpuInfo(@RequestBody SpuInfo spuInfo) {
        spuInfoService.saveSpuInfo(spuInfo);
        return Result.ok("成功");
    }

}
